package com.own.component.common.util.encrypt.util;

import com.own.component.common.util.encrypt.BaseEncryptUtil;
import com.own.component.common.util.encrypt.EncryptUtil;
import com.own.component.common.util.encrypt.model.CustomEncryptKey;

/**
 * RsaPublicUtil
 *
 * @author chenxueli
 * @date 2022-10-25 20:14:00
 */
public class RsaPublicUtil implements BaseEncryptUtil {

    private static final String PRIVATE_KEY = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANsdu7ONFebQBPsC4gRBoh8JgCpy0fcRr25FAdZepldoYi8ku6hGDihA29vGDOJ78sRa81hXLVJcuFJHKur4yjLs1Dict1+6uBdFESS7J3NkSB+MadqhHbyoPdZ6QkLg4x3qAqkTfgq1ykV7kHzJ/7GU6cGIHav5CklXoJyqx+JHAgMBAAECgYBYgMb6/AaXpvgMBxsRiw0Xqje5bY0/VUZdrMPUOYDIl2HpFtYxXrKDMcdcGr/Djzr8cpwN15B3zvmoShScuga5EXIw4Eaayq91u/2tKgG+YYFowCyviR69FKQJzcJYrRuuw7GBkxt73QPV3+GPGpFmVT5/YP+7j/9g55N6CxffCQJBAOBhbFbkrXx1HFI2A44cW0W6uOIX2hxQzWmeKzH7LUczJsgTYiwOs0Nj9h3bsFY9DNGyjQK6lxKMZ4Y86W5ArZMCQQD5/mUoDRk5+ZfMMAAdLxECP1qZmFKHxsqi6RE+x4KxrXO/uTQ7sBHSIC/cXNTsN4mXMfApcbLeUgGCljcaqUj9AkEAxbMRUj6K3W4SVh1hZIV3piivXgbGFszbMIQ8av11F5bqRL9PcKJDMM2SvRwkcte3w8wekpj1I1KypIRm6M30IQJBAMFKYQxGlGqvAR9vPadS7OO/+F0p2SYCHks3yY2w1OxsIELs/+XmjODa4iaP4FGD3253vilNL++VmHVPj+udWEECQBYAB5vnOqr55x2ecupmqo1b58jRUdGMZhk06XDSEcU22v9qxeJi36TvxpDwF0pVtr46poBCx4AbutvFu3mBaEY=";
    private static final String PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDbHbuzjRXm0AT7AuIEQaIfCYAqctH3Ea9uRQHWXqZXaGIvJLuoRg4oQNvbxgzie/LEWvNYVy1SXLhSRyrq+Moy7NQ4nLdfurgXRREkuydzZEgfjGnaoR28qD3WekJC4OMd6gKpE34KtcpFe5B8yf+xlOnBiB2r+QpJV6CcqsfiRwIDAQAB";

    private final CustomEncryptKey customEncryptKEY;

    {
        customEncryptKEY = CustomEncryptKey.builder()
                .publicKey(PUBLIC_KEY)
                .privateKey(PRIVATE_KEY)
                .build();
    }

    /**
     * 加密
     *
     * @param content 加密内容
     * @return 加密后的内容
     */
    @Override
    public String encrypt(String content) {
        return EncryptUtil.RSA.encrypt(content, customEncryptKEY);
    }

    /**
     * 解密
     *
     * @param content 解密内容
     * @return 解密后的内容
     */
    @Override
    public String decrypt(String content) {
        return EncryptUtil.RSA.decrypt(content, customEncryptKEY);
    }

}
